package demo.websocket.server.example3.rocketmq;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

/**
 * @author zhangjg
 * @desc
 * @date 2023/05/27 15:24
 **/
@Component
@RocketMQMessageListener(topic = "publicTopic", consumerGroup = "c1", selectorExpression = "*")
public class SubPublicTopic implements RocketMQListener<String> {

    private static final Logger logger = LoggerFactory.getLogger(SubPublicTopic.class);

    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;

    @Override
    public void onMessage(String message) {
        simpMessagingTemplate.convertAndSend("/topic/periodic",message);
        logger.info("订阅到广播消息 msg={}",message);
    }
}
